package com.boom.monitor.controller;

import com.boom.common.annotation.Log;
import com.boom.common.core.controller.BaseController;
import com.boom.common.core.domain.AjaxResult;
import com.boom.common.core.page.TableDataInfo;
import com.boom.common.enums.BusinessType;
import com.boom.common.utils.poi.ExcelUtil;
import com.boom.monitor.domain.MonitorConfig;
import com.boom.monitor.service.BoomConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 配置Controller
 *
 * @author yzw
 * @date 2021-03-23
 */
@RestController
@RequestMapping("/monitor/config")
public class MonitorConfigController extends BaseController {

	@Resource
	private BoomConfigService monitorBoomConfigService;

	/**
	 * 查询配置列表
	 */
	@PreAuthorize("@ss.hasPermi('monitor:config:list')")
	@GetMapping("/list")
	public TableDataInfo list(MonitorConfig monitorConfig) {
		startPage();
		List<MonitorConfig> list = monitorBoomConfigService.selectMonitorConfigList(monitorConfig);
		return getDataTable(list);
	}

	/**
	 * 导出配置列表
	 */
	@PreAuthorize("@ss.hasPermi('monitor:config:export')")
	@Log(title = "配置", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(MonitorConfig monitorConfig) {
		List<MonitorConfig> list = monitorBoomConfigService.selectMonitorConfigList(monitorConfig);
		ExcelUtil<MonitorConfig> util = new ExcelUtil<MonitorConfig>(MonitorConfig.class);
		return util.exportExcel(list, "config");
	}

	/**
	 * 获取配置详细信息
	 */
	@PreAuthorize("@ss.hasPermi('monitor:config:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") String id) {
		return AjaxResult.success(monitorBoomConfigService.selectMonitorConfigById(id));
	}

	/**
	 * 新增配置
	 */
	@PreAuthorize("@ss.hasPermi('monitor:config:add')")
	@Log(title = "配置", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody MonitorConfig monitorConfig) {
		return toAjax(monitorBoomConfigService.insertMonitorConfig(monitorConfig));
	}

	/**
	 * 修改配置
	 */
	@PreAuthorize("@ss.hasPermi('monitor:config:edit')")
	@Log(title = "配置", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody MonitorConfig monitorConfig) {
		return toAjax(monitorBoomConfigService.updateMonitorConfig(monitorConfig));
	}

	/**
	 * 删除配置
	 */
	@PreAuthorize("@ss.hasPermi('monitor:config:remove')")
	@Log(title = "配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable String[] ids) {
		return toAjax(monitorBoomConfigService.deleteMonitorConfigByIds(ids));
	}
}
